package hn.cch.druid.Controller;

import com.google.gson.Gson;
import hn.cch.druid.entity.User;
import hn.cch.druid.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author CCH
 * @version 2018.09.18
 */

@RestController
@RequestMapping("/user")
public class UserController {

    private static Logger logger = LoggerFactory.getLogger(UserController
            .class);

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/id", method = RequestMethod.POST)
    public String id(ModelMap modelMap, Long id){
        User user = userService.selectById(id);
        modelMap.addAttribute("user", user);

        Gson gson = new Gson();
        String value  = gson.toJson(user);
        logger.info(value);

        return "index";
    }


}
